#include <cstring>
#include <iostream>
#include <algorithm>

#define f(x, l, r) for (int x = l; x <= r ; ++ x)

using namespace std;

typedef long long LL;

const int N = 60, M = 40;

int n;
int w[N];
LL f[N][N][M];

void add(LL a[], LL b[] ) {
    static LL c[M];
    memset(c, 0, sizeof c);
    for (int i = 0, t = 0; i < M; ++ i) {
        t += a[i] + b[i];
        c[i] = t % 10;
        t /= 10;
    }
    memcpy(a, c, sizeof c);
}

void mul(LL a[], int b) {
    static LL c[M];
    memset(c, 0, sizeof c);
    LL t = 0;
    f (i, 0, M - 1) {
        t += a[i] * b;
        c[i] = t % 10;
        t /= 10;
    }
    memcpy(a, c, sizeof c);
}

int cmp(LL a[], LL b[]) {
    for (int i = M - 1; i >= 0; -- i)
        if (a[i] > b[i]) return 1;
        else if (a[i] < b[i]) return -1;
    return 0;
}

void print(LL a[]) {
    int k = M - 1;
    while (!a[k] && k) k -- ;
    for (int i = k; i >= 0; -- i) printf("%lld", a[i]);
}

int main() {
    cin >> n;
    
    f (i, 1, n) scanf("%d", w + i);
    
    LL temp[M];
    f (len, 3, n) 
        f (l, 1, n + 1 - len) {
            int r = l + len - 1;
            f[l][r][M - 1] = 1;
            f (k, l + 1, r - 1) {
                memset(temp, 0, sizeof temp);
                temp[0] = w[l];
                mul(temp, w[k]), mul(temp, w[r]);
                add(temp, f[l][k]), add(temp, f[k][r]);
                if (cmp(f[l][r], temp) > 0) memcpy(f[l][r], temp, sizeof temp);
            }
        }
        
    print(f[1][n]);
    
    return 0;
}